﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AcDotNetTool;
namespace _04用户交互
{
    public  class CircleJig:EntityJig
    {
        
        private double jRadius;
        public CircleJig(Point3d center)
            : base(new Circle())
        {
            ((Circle)Entity).Center = center;
        }
        //用于更新图形对象,这个更新属性是不需要使用事务处理
        protected override bool Update()
        {
            //动态更新园的半径
            if (jRadius > 0)
            {
                ((Circle)Entity).Radius = jRadius;
            }
            
            return true;
        }
        //这个函数的作用是当鼠标在屏幕上移动时,就会被调用,实现这个函数时,一般是用它改变的门图形的属性(我们在这个类里定义的属性)
        protected override SamplerStatus Sampler(JigPrompts prompts)
        {
            //声明jig提示信息
            JigPromptPointOptions jppo = new JigPromptPointOptions("\n 请指定园上的一个点");
            char space = (char)32; 
            jppo.Keywords.Add("U");
            jppo.Keywords.Add(space.ToString());
            jppo.UserInputControls = UserInputControls.Accept3dCoordinates;
            jppo.Cursor = CursorType.RubberBand;
            jppo.BasePoint = ((Circle)Entity).Center;
            jppo.UseBasePoint = true;
            
            //获取拖拽时鼠标的位置状态
            PromptPointResult ppr =  prompts.AcquirePoint(jppo);
            jRadius = ppr.Value.GetDistanceBetweenTwoPoint(((Circle)Entity).Center);
            return SamplerStatus.NoChange;
            
        }
        public Entity GetEntity()
        {
            return Entity;
        }
    }
}
